home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 037a / tpfast40.zip / T_STR.PAS < prev    next >
Pascal/Delphi Source File  |  1991-11-15  |  4KB  |  141 lines

  1. uses crt,tpfast;
  2.  
  3. type
  4.     wholescreen           = array [1..(80 * 25) * 2] of byte;
  5.  
  6. var str                   :stype;
  7.     scrn1                 :wholescreen;
  8.     scrn2                 :wholescreen;
  9.     flag                  :boolean;
  10.     ch                    :word;
  11.  
  12.  
  13. { -------------------------------------------------------------------------- }
  14. procedure init;
  15.  
  16. begin
  17.   str := 'Strings examples using the TPFAST toolbox.';
  18. end;
  19.  
  20. { -------------------------------------------------------------------------- }
  21. procedure screen1;
  22.  
  23. begin
  24.   clrscr;
  25.   init;
  26.   dspln(str);
  27.   changechar(str,'s','@');
  28.   dspln(str);
  29.   init;
  30.   deletechar(str,'e');
  31.   dspln(str);
  32.   init;
  33.   deleteleft(str,'x');
  34.   dspln(str);
  35.   init;
  36.   deleteright(str,'A');
  37.   dspln(str);
  38.   init;
  39.   str := leftend(str,'u');
  40.   dspln(str);
  41.   init;
  42.   str := rightend(str,'u');
  43.   dspln(str);
  44.   init;
  45.   uppercase(str);
  46.   dspln(str);
  47.   init;
  48.   lowercase(str);
  49.   dspln(str);
  50.   init;
  51.   overwrite(str,'THE',24);
  52.   dspln(str);
  53.   init;
  54.   replace(str,'fastest',28,6);
  55.   dspln(str);
  56.  
  57.   dspat('line 1,               - standard string.',1,13,yellow);
  58.   dspat('line 2,  changechar   - changes all "s" to "@"',1,14,yellow);
  59.   dspat('line 3,  deletechar   - deletes all occurances of "e"',1,15,yellow);
  60.   dspat('line 4,  deleteleft   - from the left deletes all chars upto "x"',1,16,yellow);
  61.   dspat('line 5,  deleteright  - from the right deletes all chars upto "A"',1,17,yellow);
  62.   dspat('line 6,  leftend      - left end of a string uto char "u"',1,18,yellow);
  63.   dspat('line 7,  rightend     - right end of a string uto char "u"',1,19,yellow);
  64.   dspat('line 8,  uppercase    - converted to upper case',1,20,yellow);
  65.   dspat('line 9,  lowercase    - converted to lower case',1,21,yellow);
  66.   dspat('line 10, overwrite    - overwrote "THE" at position 24',1,22,yellow);
  67.   dspat('line 11, replace      - replaced "TPFAST" with "fastest"',1,23,yellow);
  68.   fillscreen(' ',1,25,80,25,blue+_cyan);
  69.   dspat('Strings demo  screen 1  - press + and - keys to toggle screens',1,25,blue+_cyan);
  70.   savescreen(@scrn1,1,1,80,25);
  71. end;
  72.  
  73. { -------------------------------------------------------------------------- }
  74. procedure screen2;
  75.  
  76. begin
  77.   clrscr;
  78.   init;
  79.   padleft(str,'_',60);
  80.   dspln(str);
  81.   init;
  82.   padright(str,'_',60);
  83.   dspln(str);
  84.   init;
  85.   padcentre(str,'_',30,60);
  86.   dspln(str);
  87.   init;
  88.   padends(str,'_',60);
  89.   dspln(str);
  90.   init;
  91.   str := stringend(str,10);
  92.   dspln(str);
  93.   init;
  94.   str := stringof('hello ',60);
  95.   dspln(str);
  96.   init;
  97.   writeln('String "the" found at pos = ',seekstring(str,'the',1));
  98.   init;
  99.   writeln('Number of words           = ',wordcount(str));
  100.   writeln('Compare strings           = ',compare(str,str));
  101.  
  102.   dspat('line 1,  padleft      - padded left to 60 with char "_"',1,13,yellow);
  103.   dspat('line 2,  padright     - padded right to 60 with char "_"',1,14,yellow);
  104.   dspat('line 3,  padcentre    - padded from "TP"  to 60 with char "_"',1,15,yellow);
  105.   dspat('line 4,  padends      - padded ends to 60 with char "_"',1,16,yellow);
  106.   dspat('line 5,  stringend    - the last 10 chars',1,17,yellow);
  107.   dspat('line 6,  stringof     - made a string[60] of "hello "',1,18,yellow);
  108.   dspat('line 7,  seekstring   - search for substring in string',1,19,yellow);
  109.   dspat('line 8,  wordcount    - number of words in string',1,20,yellow);
  110.   dspat('line 9,  compare      - compares two strings',1,21,yellow);
  111.   fillscreen(' ',1,25,80,25,blue+_cyan);
  112.   dspat('Strings demo  screen 2  - press + and - keys to toggle screens',1,25,blue+_cyan);
  113.   savescreen(@scrn2,1,1,80,25);
  114. end;
  115.  
  116. { -------------------------------------------------------------------------- }
  117.  
  118. begin
  119.   textattr := white;
  120.   cursoroff;
  121.   flag := true;
  122.   screen1;
  123.   screen2;
  124.    repeat
  125.    ch := getkey;
  126.     if (chr(lo(ch))) in ['+','-'] then
  127.     begin
  128.     if flag then
  129.           begin
  130.               restorescreen(@scrn1,1,1,80,25);
  131.               flag := false;
  132.           end
  133.         else
  134.           begin
  135.               restorescreen(@scrn2,1,1,80,25);
  136.               flag := true;
  137.           end;
  138.     end;
  139.    until ch = Esc;
  140.  cursoron;
  141. end.